package com.common.model;

import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 * 二叉树
 *
 * @author think
 * @version 1.0.0
 */
@Setter
@Getter
@NoArgsConstructor
@EqualsAndHashCode
public class TreeNode<T> {

    /**
     * 结点数据
     */
    private T value;

    /**
     * 父亲节点引用，若无则为null
     */
    private TreeNode<T> parent;

    /**
     * 左孩子
     */
    private TreeNode<T> leftChild;

    /**
     * 右孩子
     */
    private TreeNode<T>  rightChild;

    /**
     * 构造函数
     *
     * @param data 当前节点
     */
    public TreeNode(T data) {
        this.value = data;
        this.leftChild = null;
        this.rightChild = null;
    }

    /**
     * 访问当前节点的数据
     */
    public void visit() {
        System.out.printf("%s ", this.value);
    }
    
    @Override
    public String toString(){
        return "Value is: " + value;
    }
}
